<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href='<?php echo base_url()?>'>
<link rel="stylesheet" type="text/css" href="public/common/css/common.css"/>
<link rel="stylesheet" type="text/css" href="public/admin/css/admin.css"/>
<script src="public/common/js/jquery.js"></script>
<script>
$(function(){
	$('select[name="category_id"]').val("<?php echo $this->input->get('category_id')?>");
	$('input[name="key_words"]').val("<?php echo $this->input->get('key_words')?>");
		$('.table tr').hover(function(){
		$(this).children('td').css('background','#ccffcc');
	},function(){
		$(this).children('td').css('background','white');
	});
})
function select_all()
{
	$('.table').find('input:checkbox').attr('checked',true);
}
function select_other()
{
	check_obj = $('.table').find('input:checked');
	$('.table').find('input:checkbox').attr('checked',true);
	check_obj.attr('checked',false);
}
function del(obj,block_id)
{
	$.post('<?php echo site_url("admin/block/delete_block")?>',{block_id:block_id},function(result){
		if(result == '1')
		{
			$(obj).parent().parent().remove();
		}else{
			alert('删除失败！');
		}
	});	
}
function delete_block(obj,block_id)
{
	if(confirm('确定要删除吗？删除后不可恢复！'))
	{
		del(obj,block_id);	
	}
}
function delete_select_block()
{
	if(confirm('确定删除所选吗？删除后不可恢复！'))
	{
		$('input:checked').each(function(){
			del(this,$(this).val());
		});
	}	
}
</script>
</head>
<body>
	<div class="body">
    	<?php echo $this->position->get_position();?>
        <div class="body_center">
        	<form action="<?php echo site_url('admin/block/index')?>" method="get">
            </form>
            	<table class="table">
                	<tr><th>选择</th><th>片段标题</th><th>片段内容</th><th>操作</th></tr>
                    	<?php if(empty($block)):?>
                        	<tr><td colspan="4" align="center">没有任何数据</td></tr>
                        <?php else:?>
							 <?php foreach($block->result() as $value):?>
                            <tr>
                                <td align="center"><input type="checkbox" value="<?php echo $value->block_id?>"></td>
                                <td align="center"><?php echo substr($value->block_name,0,60)?></td>
                       
                                <td align="center"><?php echo $value->block_content?></td>
                               
                                <td align="center"><a href="<?php echo site_url('admin/block/block_edit/'.$value->block_id)?>">修改</a> | <a href="javascript:void(0)" onclick="delete_block(this,<?php echo $value->block_id?>)">删除</a></td>
                            </tr>
                            <?php endforeach;?>
                        <?php endif;?> 	
                     <tr>
                         <td colspan="4" align="right">
                            <input type=button class="submit" value="全选" onclick="select_all()"> 
                            <input type=button onclick="select_other()" class="submit" value="反选"> 
                            <input type=button value="删除" class="button" onclick="delete_select_block()">
                         </td>
               		 </tr>
                </table>
        </div>
        <div class="page"><?php echo $page?></div>
    </div>
</body>
</html>